package objectsDiagram;

import java.awt.Dimension;
import java.util.LinkedList;
import java.util.Vector;

public class Diagram implements Cloneable{
	private String id;
	private Dimension size;
	private Vector<Task> tasks;
	private Vector<Condition> conditions;
	private Vector<Input> inputs;
	private Vector<Output> outputs;
	private Vector<Flow> flows;
	private LinkedList<Diagram> diagrams; 
	public int xPrevMouse;
	public int yPrevMouse;
	
	public Diagram(){
		tasks = new Vector<Task>();
		inputs = new Vector<Input>();
		outputs = new Vector<Output>();
		conditions = new Vector<Condition>();
		flows = new Vector<Flow>();
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Dimension getSize() {
		return size;
	}

	public void setSize(Dimension size) {
		this.size = size;
	}

	public LinkedList<Diagram> getDiagrams() {
		return diagrams;
	}

	public void setDiagrams(LinkedList<Diagram> diagrams) {
		this.diagrams = diagrams;
	}

	public Vector<Task> getTasks() {
		return tasks;
	}

	public void setTasks(Vector<Task> tasks) {
		this.tasks = tasks;
	}

	public Vector<Condition> getConditions() {
		return conditions;
	}

	public void setConditions(Vector<Condition> conditions) {
		this.conditions = conditions;
	}

	public Vector<Input> getInputs() {
		return inputs;
	}

	public void setInputs(Vector<Input> inputs) {
		this.inputs = inputs;
	}

	public Vector<Output> getOutputs() {
		return outputs;
	}

	public void setOutputs(Vector<Output> outputs) {
		this.outputs = outputs;
	}

	public Vector<Flow> getFlows() {
		return flows;
	}

	public void setFlows(Vector<Flow> flows) {
		this.flows = flows;
	}
	
	public void cleanDiagram(){
		this.tasks.clear();
		this.conditions.clear();
		this.flows.clear();
		this.outputs.clear();
		this.inputs.clear();
	}
	
    public Diagram clone(){
    	Diagram obj=null;
        obj= new Diagram();
        obj.id = this.getId();
        obj.setSize(new Dimension(this.getSize().width, this.getSize().height));
		obj.conditions = new Vector<Condition>();
		for(int i=0;i<conditions.size();i++){
			Condition newCondition = conditions.get(i).clone();
			obj.conditions.add(newCondition);
			for(int j=0;j<newCondition.getFlowsIn().size();j++){
				obj.flows.add(newCondition.getFlowsIn().get(j));
			}
		}
		obj.tasks = new Vector<Task>();
		for(int i=0;i<tasks.size();i++){
			Task newTask = tasks.get(i).clone();
			if(tasks.get(i).getDecorJoin()!=null)
				newTask.setDecorJoin(tasks.get(i).getDecorJoin().clone());
			if(tasks.get(i).getDecorSplit()!=null)
				newTask.setDecorSplit(tasks.get(i).getDecorSplit().clone());
			obj.tasks.add(newTask);
			for(int j=0;j<newTask .getFlowsIn().size();j++){
				obj.flows.add(newTask.getFlowsIn().get(j));
			}
		}
		obj.inputs = new Vector<Input>();
		for(int i=0;i<inputs.size();i++)
			obj.inputs.add(inputs.get(i).clone());
		obj.outputs = new Vector<Output>();
		for(int i=0;i<outputs.size();i++)
			obj.outputs.add(outputs.get(i).clone());
		obj.flows = new Vector<Flow>();
		/*for(int i=0;i<flows.size();i++)
			obj.flows.add(flows.get(i).clone());*/
		return obj;
    }

	@Override
	public String toString() {
		return "Diagram [id=" + id + ", size=" + size + ", tasks=" + tasks
				+ ", conditions=" + conditions + ", inputs=" + inputs
				+ ", outputs=" + outputs + ", flows=" + flows + ", diagrams="
				+ diagrams + ", xPrevMouse=" + xPrevMouse + ", yPrevMouse="
				+ yPrevMouse + "]";
	}
    
    
}
